package chamans.away
{
	import away3d.containers.ObjectContainer3D;
	import away3d.entities.Mesh;
	import away3d.materials.BitmapMaterial;
	import away3d.materials.methods.EnvMapDiffuseMethod;
	import flash.geom.*;
	
	public class crate
	{
		private var BASE:Object;
		private var intern:Mesh;
		public var end:Function;
		private var Pos:Vector3D;
		private var mat:BitmapMaterial;
		private var m_liste:Vector.<Mesh>;
		private var mat_liste:Vector.<BitmapMaterial>;
		
		public function crate(base:Object, END:Function=null, P:Vector3D=null)
		{
			BASE=base; end=END || new Function();
			mat_liste = new Vector.<BitmapMaterial>();
			BASE.LOAD.IMGLIST("assets/demobullet/crate/", ['stebox2_d', "sopbox2_s", "sopbox2_local", "stebox1_d" , "sopbox2a" , "cube_d", "cube_s", "cube_local"], initMaterials , ".jpg")	
		}
		private function initMaterials( A:Array  ) : void
		{
			var mat0:BitmapMaterial = new BitmapMaterial(A[0]);
			var mat2:BitmapMaterial = new BitmapMaterial(A[3]);
			var mat3:BitmapMaterial = new BitmapMaterial(A[4]);
			var mat4:BitmapMaterial = new BitmapMaterial(A[5]);
			var n:int=0
			mat_liste.push(mat0)
			mat_liste.push(mat2)
			mat_liste.push(mat3)
			mat_liste.push(mat4)
			for each(var mat:BitmapMaterial in mat_liste){
				mat.lights = BASE.LIGHT;
				mat.ambientColor = BASE.FogColor;
				mat.specularMap = A[1];
				mat.normalMap = A[2];
				mat.ambient=.16;
				mat.gloss = 30;
				mat.specular = 1.25;
				mat.name="Crate_"+n;
				if(BASE.fog)BASE.F_Fog(mat);
				n++;
			}
			mat4.specularMap = A[6]
			mat4.normalMap = A[7]
			
			BASE.MatListe.push(mat0,mat2,mat3,mat4)
			m_liste = new Vector.<Mesh>()
			BASE.OBJ3D('assets/demobullet/crate/crate.obj', Define)
			
		}
		private function Define(obj:ObjectContainer3D) : void
		{
			intern = obj.getChildAt(0) as Mesh;
			end(intern)
		}
		public function clone(P:Vector3D=null) : void
		{
			if(!P)Pos=new Vector3D(BASE.TOOL.Ran(1000, -1000),BASE.TOOL.Ran(400,80) , BASE.TOOL.Ran(500, 300)); else Pos=P;
			var D:int=BASE.TOOL.Ran(3)
			var mesh:Mesh = intern.clone() as Mesh;
			mesh.material=mat_liste[D]
			
			if(!BASE.phyOn) mesh.position = Pos;
			BASE.view.scene.addChild(mesh);
			m_liste.push(mesh);
			end(mesh, Pos)
		}
}}
